ILI9341搭載2.8インチSPI制御タッチパネル付TFT液晶 MSP2807
240x320ドットの 、チップはILI9341です
タッチパネルのコントローラーチップはXPT2046です
解説 => ILI9341用タッチパネルコントローラーチップ、XPT2046をArduinoで使う
製品
https://akizukidenshi.com/catalog/g/gM-16265/
参考資料
https://okiraku-camera.tokyo/blog/?p=6487
http://try3dcg.world.coocan.jp/note/spi/ILI9341.html
http://denshikit.main.jp/topf/technology97.html <= カラー有機EL SSD1331 の記事なのでちょっと違う
アマゾンのレビュー欄にあった画像
https://gyazo.com/76f0cb721024855f0cb1e1d2b7702552
参考動画
https://www.youtube.com/watch?v=JGIdd8FkQFk&t=122s
https://www.youtube.com/watch?v=bi6dMLkTylc
https://gyazo.com/eceb085b6e5587da0e6062d053a7ad21
https://gyazo.com/da69ac8f704f727fcf06630231c95ce8
https://www.youtube.com/watch?v=UAqyy7OqpZY
https://www.youtube.com/watch?v=9CxZ8JUu4fo&t=82s
arduinnoで使う場合、8ビット双方向ロジックレベル変換モジュールが必用
https://akizukidenshi.com/catalog/g/gM-04522/
https://www.amazon.co.jp/gp/product/B0B6NC4KPM/ref=ox_sc_act_title_1?smid=A3J16E5CPEQSPH&th=1
KEYESTUDIO Plus Board for Arduino UNO R3なら、自力で3.3Vにロジックレベルを変更できるので不要
wokwi(シミュレーター) において
https://wokwi.com/projects/354601132577803265 <= 使用中
https://gyazo.com/b6444145436b4617f6017fa3506ed138
tft.drawRect(x, y, w, h, color) の後に、yield() を入れないとバグる
uint16_t color565(uint8_t r, uint8_t g, uint8_t b) で任意の色を生成できる。直接 unit16_t blue = 0x2d5fのように宣言して使うこともできる
RGB565 方式
https://chrishewett.com/blog/true-rgb565-colour-picker/
ここで16bitカラーが生成できる
ライブラリ
https://github.com/adafruit/Adafruit-GFX-Library
リファレンス http://adafruit.github.io/Adafruit-GFX-Library/html/class_adafruit___g_f_x.html
charレンダリングの仕組み
code:Adafruit_GFX.cpp
//https://github.com/ehubin/Adafruit-GFX-Library/blob/master/Adafruit_GFX.cpp 372~
// draw a character
void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c,
uint16_t color, uint16_t bg, uint8_t size) {
if((x >= _width) || // Clip right
(y >= _height) || // Clip bottom
((x + 5 * size - 1) < 0) || // Clip left
((y + 8 * size - 1) < 0)) // Clip top
return;
for (int8_t i=0; i<6; i++ ) {
uint8_t line;
if (i == 5)
line = 0x0;
else
line = pgm_read_byte(font+(c*5)+i);
for (int8_t j = 0; j<8; j++) {
if (line & 0x1) {
if (size == 1) // default size
drawPixel(x+i, y+j, color);
else { // big size
fillRect(x+(i*size), y+(j*size), size, size, color);
}
} else if (bg != color) {
if (size == 1) // default size
drawPixel(x+i, y+j, bg);
else { // big size
fillRect(x+i*size, y+j*size, size, size, bg);
}
}
line >>= 1;
}
}
}
https://github.com/adafruit/Adafruit_ILI9341
Adafruit_ILI9341ライブラリをincludeすると使える定数 https://github.com/adafruit/Adafruit_ILI9341/blob/master/Adafruit_ILI9341.h
Adafruit_ILI9341はAdafruit-GFX-Libraryを継承しているので、Adafruit-GFX-Library側の資料も参考にすること
TFT.setTextSize()
文字列のサイズを設定する。デフォルトサイズは"1"である。サイズを1増やすと、高さが10ピクセル増える。size 1が10ピクセル、size 2が20ピクセル、…である。
実際に試したところ、横はサイズ(1,2,3,4,....) * 6px であった
日本語の表示方法
ライブラリではASCII 文字しかレンダリングできないので、ひらがなカタカナ漢字を表示するには、ビットマップを作成する必要がある
https://yokahiyori.com/esp32-devkitc_ili9341-lcd_scd30_bme280_ds3121/
このスケッチで使った漢字と記号は「C、O、気、圧、温、湿、度、(℃)」と少ないので、メモリ消費を抑えるために、利用する特定の文字のみをBMPファイルから変換したHEXデータで表示します。
漢字や記号のBMPファイルは、Windows標準アプリのペイント3Dで170×170ピクセル程度で作った後キャンパスを32×32ピクセル(「(℃)」のみ40×40ピクセル)に変更して圧縮します。このBMPファイルをHEXデータに変換してtft.drawXBitmap() で描画します。
ビットマップを作成するには、lcd-image-converter.exe を使うとよい
設定でRGB565 方式の出力ができる